<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    :root {
      --gradient: linear-gradient(to right,purple,
      red, orange, yellow,green, cyan, blue, purple,
      red, orange, yellow,green, cyan, blue, purple)
    }
    #text {
      background: var(--gradient);
      -webkit-background-clip:text;
      color: transparent;
      font-size: 80px;
      font-family: "Arial Black";
      background-size: 200%;
      background-position:0;
    }

    .btn:checked ~ #text {
      animation: showAni 3s linear infinite;
    }

    .btn:checked ~ label {
      background-color: thistle;
    }

    @keyframes showAni{
      0% {
        background-position-x:0%
      }
      100% {
        background-position-x:100%
      }
    }

  </style>
</head>
<body>
  <div class="wrap">
    <input type="checkbox" id="ip" class="btn">
    <label for="ip">点我播动画</label>
    <p id="text">Hello Mcgee</p>
  </div>
</body>
</html>